'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _react = require('react');

var React = _interopRequireWildcard(_react);

var _checkbox = require('../checkbox');

var _checkbox2 = _interopRequireDefault(_checkbox);

var _inputNumber = require('../input-number');

var _inputNumber2 = _interopRequireDefault(_inputNumber);

var _ColumnFilterMenu = require('./ColumnFilterMenu');

require('../input-number/style');

require('../checkbox/style');

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }



// 引入组件后 还需引入对应的样式
/**
 * @date 2019-01-21

 */
var sortInputStyle = {
    width: '60px'
};
var sortInputWrapStyle = (0, _extends3['default'])({}, sortInputStyle, { display: 'inline-block' });
var sortInputWrapStyleCenter = (0, _extends3['default'])({}, sortInputWrapStyle, { textAlign: 'center' });

var ColumnFilterMenuItem = function (_React$Component) {
    (0, _inherits3['default'])(ColumnFilterMenuItem, _React$Component);

    function ColumnFilterMenuItem(props) {
        (0, _classCallCheck3['default'])(this, ColumnFilterMenuItem);

        // 修改是否 lock (fixedLeft)
        var _this = (0, _possibleConstructorReturn3['default'])(this, (ColumnFilterMenuItem.__proto__ || Object.getPrototypeOf(ColumnFilterMenuItem)).call(this, props));

        _this.handleFixedLeftChange = function (e) {
            var customColumn = _this.state.customColumn;

            var fixedLeft = e.target.checked ? 1 : 0;
            _this.setState({
                customColumn: (0, _extends3['default'])({}, customColumn, { fixedLeft: fixedLeft, fixedRight: fixedLeft === 1 ? 0 : customColumn.fixedRight })
            });
        };
        // // 修改 fixedRight
        // handleFixedRightChange = (e: CheckboxChangeEvent) => {
        //   const { customColumn } = this.state;
        //   const fixedRight = e.target.checked ? 1 : 0;
        //   this.setState({
        //     customColumn: {
        //       ...customColumn,
        //       fixedRight,
        //       fixedLeft: (fixedLeft === 1) ? 0 : customColumn.fixedLeft, // 如果 fixedRight 为 1,则 fixedLeft 为 0
        //     },
        //   });
        // }
        // 修改是否隐藏
        _this.handleHiddenChange = function (e) {
            var customColumn = _this.state.customColumn;

            var hidden = e.target.checked ? 0 : 1;
            _this.setState({
                customColumn: (0, _extends3['default'])({}, customColumn, { hidden: hidden })
            });
        };
        // 修改排序
        _this.handleOrderSeqChange = function (value) {
            var customColumn = _this.state.customColumn;

            _this.setState({
                customColumn: (0, _extends3['default'])({}, customColumn, { orderSeq: value })
            });
        };
        // 获取校验的数据
        _this.getValidateCustomColumn = function () {
            var customColumn = _this.state.customColumn;

            return Promise.resolve(customColumn);
        };
        var customColumn = props.customColumn || {
            hidden: 0,
            fixedLeft: 0,
            fixedRight: 0,
            orderSeq: props.index,
            fieldKey: (0, _ColumnFilterMenu.getColumnKey)(props.column, props.index)
        };
        _this.state = {
            customColumn: customColumn,
            prevCustomColumn: customColumn
        };
        return _this;
    }

    (0, _createClass3['default'])(ColumnFilterMenuItem, [{
        key: 'render',
        value: function render() {
            var column = this.props.column;
            var customColumn = this.state.customColumn;
            // <div
            //   style={sortInputWrapStyleCenter}
            // >
            //   <Checkbox
            //     name="fixedRight"
            //     checked={customColumn.fixedRight === 1}
            //     onChange={this.handleFixedRightChange}
            //     checkedValue={1}
            //     unCheckedValue={0}
            //   />
            // </div>

            return React.createElement(
                React.Fragment,
                null,
                React.createElement(
                    'div',
                    { style: sortInputWrapStyleCenter },
                    React.createElement(_checkbox2['default'], { style: sortInputStyle, checked: customColumn.hidden !== 1, onChange: this.handleHiddenChange })
                ),
                React.createElement(
                    'div',
                    { className: 'dropdown-menu-text' },
                    column.title
                ),
                React.createElement(
                    'div',
                    { style: sortInputWrapStyleCenter },
                    React.createElement(_checkbox2['default'], { name: 'fixedLeft', checked: customColumn.fixedLeft === 1, onChange: this.handleFixedLeftChange })
                ),
                React.createElement(
                    'div',
                    { style: sortInputWrapStyle },
                    React.createElement(_inputNumber2['default'], { name: 'orderSeq', style: sortInputStyle, min: 0, step: 1, precision: 0, value: customColumn.orderSeq, onChange: this.handleOrderSeqChange })
                )
            );
        }
    }], [{
        key: 'getDerivedStateFromProps',
        value: function getDerivedStateFromProps(nextProps, prevState) {
            var customColumn = nextProps.customColumn;
            var prevCustomColumn = prevState.prevCustomColumn;

            if (customColumn && prevCustomColumn !== customColumn) {
                return {
                    customColumn: customColumn,
                    prevCustomColumn: customColumn
                };
            }
            return null;
        }
    }]);
    return ColumnFilterMenuItem;
}(React.Component);

exports['default'] = ColumnFilterMenuItem;
module.exports = exports['default'];